<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	

	protected function _initAutoload() {
		require_once 'Zend/Loader/Autoloader.php';
		$moduleLoader = new Zend_Application_Module_Autoloader ( array (
				'basePath' => APPLICATION_PATH,
				'namespace' => 'Application'
		) );
		$moduleLoader->addResourceType('app','app/','App');
		/*$moduleLoader->addResourceType('form', 'forms', 'Form')
				->addResourceType('model', 'models', 'Model')
				->addResourceType('dbtable', 'models/DbTable', 'Model_DbTable');
		*/
		$autoloader = Zend_Loader_Autoloader::getInstance ();
		$autoloader->setFallbackAutoloader ( true );
		
		return $autoloader;
	}
	
	protected function _initConnection() {
		$options = $this->getOption ( 'resources' );
		$db_adapter = $options ['db'] ['adapter'];
		$params = $options ['db'] ['params'];
		try {
			$db = Zend_Db::factory ( $db_adapter, $params );
			$db->getConnection ();
			$registry = Zend_Registry::getInstance ();
			$registry->set ( 'db', $db );
		} catch ( Zend_Exception $e ) {
			Application_Model_Util::saveLog($e);
			echo "Insira aqui a pagina inicial";
			exit ();
		}
	}
	
	
	protected function _initDocType()
	{
		$this->bootstrap('View');
		$view = $this->getResource('View');
		$view->doctype('HTML5');
        
		//-----CSS
 		$view->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' =>  'public/img/favicon.ico'));
	    $view->headLink()->appendStylesheet('public/css/principal.css');
    //JS
		$view->headScript()->appendFile( 'public/js/html5shiv.js', 'text/javascript', array('conditional' => 'lt IE 9'));
		$view->headScript()->appendFile('public/bootstrap/js/jquery.min.js')
							->appendFile('public/bootstrap/js/bootstrap.min.js');
		 
	}
	
	protected function _initConfig()
	{
	    $config = new Zend_Config($this->getOptions(), true);
	    Zend_Registry::set('config', $config);
	    return $config;
	}
	
	
	protected function _initAcl()
	{
		$aclSetup = new Application_Acl_Setup();
	}
	
	
	
	/**$usuario = Zend_Auth::getInstance()->getIdentity();
	  
	if($usuario->isAllowed($usuario->getRoleId(), $this->_name, 'index'))
	{
	echo "adsfsdfasdf";
	} else {
	//throw new Exception($user->getRole());
	$this->_helper->redirector('error', 'error');
	}
	 
	*
	* Initiate translation package in the portal register in the variable Zend_Translate and load
	* the archive.
	*
	* @access protected
	* @return null
	*/
	protected function _initLanguage()
	{
	    try
	    {
	        $translate = new Zend_Translate('csv',APPLICATION_PATH .'/languages/en.csv','en' );
	        $translate->addTranslation( APPLICATION_PATH .'/languages/br.csv', 'br');
	        Zend_Registry::set('Zend_Translate', $translate);
	    }
	    catch (Exception $e)
	    {
	        echo $e->getMessage();
	    }
	}
	
}

